import logging

from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to

from sc_console.lib.base import BaseController, render

from sc_console.model.models import ErrorReport, YouTubePartialParse
from sc_console.model.models import RawMessage
from sc_console.model.meta import Session

from advanced_json_encoding import encode

log = logging.getLogger(__name__)

class RetrievalController(BaseController):
    def retrieve_retries(self):
        results = []

        response.content_type = 'text/json'

        messages = Session.query(RawMessage).all()

        for m in messages:
            name = m.message_name
            data = m.data

            results.append( (name, data) )
            Session.delete(m)

        Session.commit()
        return encode(results)
